using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using EntLibEC.Cmn;

using EntLibEC.Info.Online;

using EntLibEC.Biz;
using EntLibEC.Biz.Online;

using EntLibEC.Info.Basic;

namespace EntLibEC.View.Online
{
	/// <summary>
	/// Summary description for FeedBackOpt.
	/// </summary>
	public partial class FeedBackOpt : PageBase
	{
		protected EntLibEC.View.Cmn.FeedBackStatus ucStatus;

		private int sysno;
		protected string bodyOnLoad;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			if ( Request.QueryString["sysno"] != null)
			{
				try
				{
					this.sysno = Convert.ToInt32(Request.QueryString["sysno"].ToString());
				}
				catch
				{
					Assert(lblMessage, "sysno is not an integer", -1);
					return;
				}
			}

			if ( !Page.IsPostBack)
			{
				ucStatus.BindStatus(false);
				BindForm();
			}
		}
		private void BindForm()
		{
			FeedBackInfo oInfo = FeedBackManager.GetInstance().Load(this.sysno);
			if ( oInfo == null )
				return;

			lblSubject.Text = oInfo.Subject;
			lblSuggest.Text = oInfo.Suggest;
			lblNickName.Text = oInfo.NickName;
			lblEmail.Text = oInfo.Email;
			lblPhone.Text = oInfo.Phone;
			txtMemo.Text = oInfo.Memo;
			txtNote.Text = oInfo.Note;
			ucStatus.StatusSysNo = oInfo.Status;

		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void btnUpdate_Click(object sender, System.EventArgs e)
		{
			if ( !base.CheckAccess((int)AppEnum.Privilege.FeedBack, false, lblMessage) )
				return;

			try
			{
				Hashtable ht = new Hashtable(5);
				ht.Add("SysNo", this.sysno);
				if ( txtMemo.Text.Trim() != "")
					ht.Add("Memo", txtMemo.Text.Trim());
				if ( txtNote.Text.Trim() != "")
					ht.Add("Note", txtNote.Text.Trim());
				ht.Add("Status", ucStatus.StatusSysNo);
				ht.Add("UpdateTime", DateTime.Now);
				FeedBackManager.GetInstance().Update(ht);
				
				LogManager.GetInstance().Write(new LogInfo(this.sysno, (int)AppEnum.LogType.Online_FeedBack_Update, base.sInfo));
				bodyOnLoad = "javascript:window.opener.__doPostBack('btnSearch','btnSearch');window.close(); return false;";
			}
			catch(BizException exp)
			{
				Assert(lblMessage, exp.Message, -1);
			}
			catch(Exception exp)
			{
				Assert(lblMessage, "update error, see log", -1);
				ErrorLog.GetInstance().Write(exp.ToString());
			}
		
		}
	}
}
